﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Sherwood.Security.KeyGenerationUtility
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Generates an RSA private/public key pair with a key length of 1024 bits.
        /// This implementation current requires the use of unmanged openSSL dlls.
        /// </summary>
        /// <param name="publicKey">Public key in PEM format.</param>
        /// <param name="privateKey">Private key in PEM format.</param>
        public static void GenerateKeyPair(out string publicKey, out string privateKey)
        {
            publicKey = null;
            privateKey = null;
            OpenSSL.Crypto.RSA rsa = new OpenSSL.Crypto.RSA();
            rsa.GenerateKeys(1024, 3, null, null);
            publicKey = rsa.PublicKeyAsPEM;
            privateKey = rsa.PrivateKeyAsPEM;
        }


        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {


            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

            string publicRsaKey = "";
            string privateRsaKey = "";
            GenerateKeyPair(out publicRsaKey, out privateRsaKey);


            txtServerXML.Text = publicRsaKey;

            txtClientKey.Text = privateRsaKey;




        }


    }
}
